package com.uzai.common.utils;

import java.util.Objects;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author mingyang.chen create in 2023/11/27 16:03
 */
public class TbMatchUtils {

    private static final Pattern itemIdMatchPattern = Pattern.compile("(?<=\\?id\\=|&id\\=)([0-9]{5,15}|[a-zA-Z0-9]{10,16}-[a-zA-Z0-9]{15,22})(?=&|$|\\.)");


    public static boolean isTbItemId(String valContent, Consumer<String> itemIdCallback) {
        Matcher matcher = itemIdMatchPattern.matcher(valContent);
        while (matcher.find()) {
            String itemId = matcher.group();
            if (Objects.nonNull(itemIdCallback)) {
                itemIdCallback.accept(itemId);
            }
            return true;
        }
        return false;
    }
}
